home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / test / filesmac.sml < prev    next >
Encoding:
Text File  |  1995-09-15  |  5.3 KB  |  160 lines  |  [TEXT/Moml]

  1. (* test/filesys.sml
  2.    PS 1995-03-23
  3. *)
  4.  
  5. (* Mac: changed "/" to ":", "." to ":", ".." to "::"
  6.         10a is testing that remove doesn't work on directories
  7.             -- it does on the Mac; this is probably OK
  8.         testcycl -> testcycl  can this be done on the Mac?
  9.         readDir doen't make "." and ".." -- commented out
  10.                 so rewindDir test is less worthwhile (but it does work!)
  11.         test13a & 13c fail because readLink fails for non-links
  12.         test13b fails because readLink makes full pathname
  13. *)
  14.  
  15. (* DOS: Plain WRONG: test6a, test9a (and test9b);
  16.         Excusable:   test8b, test11b, test12a, test13a, test13b, test13c
  17.  *)
  18.  
  19. (* This requires two links to be present in the current directory:
  20.         testlink -> README
  21.         testcycl -> testcycl 
  22.         testbadl -> exists.not
  23.    Moreover, the file README must exist and the file exists.not not.
  24. *)
  25.  
  26.  
  27. use "auxil.sml";
  28.  
  29. local
  30.     open FileSys
  31.     (* Clean up: *)
  32.     val _ = (rmDir "testdir") handle OS.SysErr _ => (); 
  33.     val _ = (rmDir "testdir2") handle OS.SysErr _ => (); 
  34. in
  35.  
  36. val test1a = (mkDir "testdir" seq "OK") handle _ => "WRONG";
  37. val test1b = (mkDir "testdir" seq "WRONG")
  38.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  39.  
  40. val test2 = check'(fn _ => isDir "testdir");
  41.     
  42. val test3 = check'(fn _ => access("testdir", [A_READ, A_EXEC, A_WRITE]));
  43.  
  44. local 
  45.     val cdir = getDir();
  46. in
  47.     val test4a = (chDir cdir seq "OK") handle _ => "WRONG";
  48.     val test4b = check'(fn _ => cdir = getDir());
  49.     val _ = chDir "testdir";
  50.     val test4c = check'(fn _ => cdir <> getDir());
  51.     val _ = chDir "::";
  52.     val test4d = check'(fn _ => cdir = getDir());
  53. end;
  54.  
  55. val _ = rename{old = "testdir", new = "exists.not"};
  56.  
  57. val test5 = (rmDir "exists.not" seq "OK") handle _ => "WRONG";
  58.  
  59. val test6a = (openDir "exists.not" seq "WRONG") 
  60.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  61. val test6b = (isDir "exists.not" seq "WRONG")
  62.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  63. val test6c = (rmDir "exists.not" seq "WRONG")
  64.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  65. val test6d = (chDir "exists.not" seq "WRONG")
  66.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  67. val test6e = (realPath "exists.not" seq "WRONG")
  68.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  69. val test6f = (modTime "exists.not" seq "WRONG")
  70.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  71. val test6g = (setTime("exists.not", NONE) seq "WRONG")
  72.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  73. val test6h = (remove "exists.not" seq "WRONG")
  74.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  75. val test6i = (rename{old="exists.not", new="testdir2"} seq "WRONG")
  76.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  77. val test6j = check'(fn _ => not (access("exists.not", [])));
  78.  
  79. val _ = mkDir "testdir";
  80.  
  81. local 
  82.     val dstr = openDir "testdir";
  83. in
  84.     val test7a = 
  85.         check'(fn _ => (* ":" = readDir dstr
  86.                andalso "::" = readDir dstr
  87.                andalso *) "" = readDir dstr);
  88.     val _ = rewindDir dstr;
  89.     val test7b = 
  90.         check'(fn _ => (* ":" = readDir dstr
  91.                andalso "::" = readDir dstr
  92.                andalso *) "" = readDir dstr);
  93.     val _ = closeDir dstr;
  94.     val test7c = (readDir dstr seq "WRONG")
  95.                  handle OS.SysErr _ => "OK" | _ => "WRONG";
  96.     val test7d = (rewindDir dstr seq "WRONG")
  97.                  handle OS.SysErr _ => "OK" | _ => "WRONG";
  98.     val test7e = (closeDir dstr seq "WRONG")
  99.                  handle OS.SysErr _ => "OK" | _ => "WRONG";
  100. end
  101.  
  102. val test8a = 
  103.     check'(fn _ => realPath ":" = getDir ());
  104. val test8b = 
  105.     check'(fn _ => realPath "testlink" = getDir() ^ ":README");
  106. val test8c = (realPath "testcycl" seq "WRONG")
  107.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  108. val test8d = (realPath "testbadl" seq "WRONG")
  109.              handle OS.SysErr _ => "OK" | _ => "WRONG";
  110.  
  111. val test9a = 
  112.     check'(fn _ => 
  113.            setTime ("README", SOME (Time.realToTime 1E6)) = ());
  114. val test9b = 
  115.     check'(fn _ => modTime "README" = Time.realToTime 1E6);
  116.     
  117. (* -- e
  118. val test10a = (remove "testdir" seq "WRONG")
  119.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  120. *)
  121. val test10a = "WRONG, because remove removes directories.";
  122. val test10b = 
  123.     check'(fn _ => 
  124.            rename{old = "testdir", new = "testdir2"} = ());
  125. val test10c = 
  126.     check'(fn _ => isDir "testdir2");
  127.  
  128. val test11a = 
  129.     check'(fn _ => not (access ("testdir", [])));
  130. val test11b = 
  131.     check'(fn _ => access("testlink", []));
  132. val test11c = 
  133.     check'(fn _ => not (access("testbadl", [])));
  134.  
  135. val test12a = 
  136.     check'(fn _ => (* isLink "testcycl" 
  137.            andalso *)  isLink "testlink"
  138.            andalso isLink "testbadl");
  139. val test12b = 
  140.     check'(fn _ => not (isLink "testdir2"
  141.                         orelse isLink "README"));
  142. val test12c = (isLink "exists.not" seq "WRONG")
  143.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  144.  
  145. val test13a = 
  146.     check'(fn _ => readLink "testcycl" = "testcycl");
  147. val test13b = 
  148.     check'(fn _ => readLink "testlink" = "README");
  149. val test13c = 
  150.     check'(fn _ => readLink "testbadl" = "exists.not");
  151. val test13d = (readLink "testdir2" seq "WRONG")
  152.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  153. val test13e = (readLink "exists.not" seq "WRONG")
  154.               handle OS.SysErr _ => "OK" | _ => "WRONG";
  155.  
  156. val test14 = (tmpName{dir=NONE, prefix=NONE} seq "OK");
  157.  
  158. val _ = rmDir "testdir2";
  159. end
  160.